*Set working drive to Main filepath (e.g. C:\Documents\) 
cd "INSERT DESIRED FILE PATH"

*Load data 
use LandgraveWeller_2020_Audit, clear

*Set working drive to Table and Figures filepath (e.g. C:\Documents\) 
cd "INSERT DESIRED FILE PATH\Tables and Figures"

			*||| MAIN ANALYSIS |||*

*Figure 1 - Reply Rate by Name's Perceived SES and Purpoted Race and Ethnicity
	
twoway lfit AvgReply Name_Work || scatter AvgReply Name_Work, ///
mlabel(PurportedRace) msymbol(none) ylab(.4 "40%" .5 "50%" .6 "60%",nogrid angle(45)) xlab(,nogrid) ///
ytitle("Reply Rate by Name") title("All Names") legend(off) saving(All, replace) graphregion(color(white))

twoway lfit AvgReply Name_Work if Race == 0 || scatter AvgReply Name_Work if Race == 0, ///
mlabel(PurportedRace) msymbol(none) ylab(.4 "40%" .5 "50%" .6 "60%",nogrid angle(45)) xlab(,nogrid) ///
ytitle("Reply Rate by Name") title("White Names") legend(off) saving(White, replace) graphregion(color(white))

twoway lfit AvgReply Name_Work if Race == 1 || scatter AvgReply Name_Work if Race == 1, ///
mlabel(PurportedRace) msymbol(none) ylab(.4 "40%" .5 "50%" .6 "60%",nogrid angle(45)) xlab(,nogrid) ///
ytitle("Reply Rate by Name") title("Black Names") legend(off) saving(Black, replace) graphregion(color(white))

twoway lfit AvgReply Name_Work if Race == 2 || scatter AvgReply Name_Work if Race == 2, ///
mlabel(PurportedRace) msymbol(none) ylab(.4 "40%" .5 "50%" .6 "60%",nogrid angle(45)) xlab(,nogrid) ///
ytitle("Reply Rate by Name") title("Hispanic Names") legend(off) saving(Hispanic, replace) graphregion(color(white))

gr combine All.gph White.gph Black.gph Hispanic.gph, ///
ycommon xcommon scheme(plotplainblind) graphregion(color(white))

graph export "Figure1.png", replace 

*Table 2 - Reply Rate by Name's Perceived Characteristics	
reg DV_Reply Races2 Races3, robust
outreg2 using "Table2.xls", replace label dec(3)
	
reg DV_Reply Name_Work, robust
outreg2 using "Table2.xls", append label dec(3)

reg DV_Reply Name_Hispanic Name_Black, robust
outreg2 using "Table2.xls", append label dec(3)
	
reg DV_Reply Name_Work Name_Black Name_Hispanic Name_Female Name_Migrant, robust
outreg2 using "Table2.xls", append label dec(3)

reg DV_Reply Name_Work Races2 Races3 Name_Female Name_Migrant, robust
outreg2 using "Table2.xls", append label dec(3)


			*||| ONLINE APPENDICES |||*

*Appendix C Table 1 – Subject Characteristics by Purported Race/Ethnicity	

*NOTE: Code/data for Table C1 omitted due to data de-identification procedure. 
			
*Appendix C Table 2 – Reply Rate by Name’s Perceived Characteristics	
reg DV_Reply Name_Work
outreg2 using "AppendixCTable2.xls", replace label dec(3)

reg DV_Reply Name_Black Name_Hispanic
outreg2 using "AppendixCTable2.xls", append label dec(3)

reg DV_Reply Name_Female
outreg2 using "AppendixCTable2.xls", append label dec(3)

reg DV_Reply Name_Migrant
outreg2 using "AppendixCTable2.xls", append label dec(3)

reg DV_Reply Name_Work Name_Black Name_Hispanic Name_Female Name_Migrant
outreg2 using "AppendixCTable2.xls", append label dec(3)

*Appendix C Table 3 – Reply Rate, SES Discrimination Moderated by District Per Capita Income
gen pipe = "|"
gen where = -2
	
reg DV_Reply Name_Work
outreg2 using "AppendixCTable3.xls", replace label dec(3)

reg DV_Reply Name_Work Income
outreg2 using "AppendixCTable3.xls", append label dec(3)

reg DV_Reply Name_Work Income IncomeSES
outreg2 using "AppendixCTable3.xls", append label dec(3)

reg DV_Reply c.Name_Work##c.Income
margins, dydx(Name_Work) at(Income=(1(1)13))

*Appendix C Figure 1 – Reply Rate, SES Discrimination Moderated by District Per Capita Income
marginsplot ///
, ///
title("SES Discrimination by State Legislative District Income") /// 
subtitle("95% CI", size(small)) ///
xtitle("State Legislative District Per Capita Income (10,000 USDs, 2017 ACS)") ///
xlabel(0 " " 1 "Min (10,000)" 3.133847 "Mean (31,338)" 5 " "  10 " " ///
13 "Max (130,000)" 15 " ", nogrid angle(15)) ///
ytitle("Predicted Difference in Reply Rates") ///
ylabel(-2 "-200 pp" -1 "-100 pp" 0 "0 pp" 1 "100 pp", nogrid) ///
yline(0) ///
scheme(plottigblind) ///
plotregion(fcolor(white)) ///
legend(off) ///
note("Negative values indicate fewer responses for lower SES names.") ///
addplot(scatter where Income, ///
mlabel(pipe) ms(none) mlabel(pipe) mlabpos(0) legend(off) )

graph export "AppendixCFigure1.png", as(png) replace

*Appendix C Table 4 – Reply Rate by Name’s Perceived Characteristics	

reg WhereRegister Races2 Races3
outreg2 using "AppendixCTable4.xls", replace label dec(3) title("DV: Did respondents explain where to register?")
	
reg WhereRegister Name_Work
outreg2 using "AppendixCTable4.xls", append label dec(3)

reg WhereRegister Name_Work Races2 Races3
outreg2 using "AppendixCTable4.xls", append label dec(3)

reg WhereRegister Name_Hispanic Name_Black
outreg2 using "AppendixCTable4.xls", append label dec(3)

reg WhereRegister Name_Work Name_Hispanic Name_Black
outreg2 using "AppendixCTable4.xls", append label dec(3)

*Appendix A Table 7a – State Legislators and MTurk Respondents' Demographics, MTurk Respondents
	*Note: See LandgraveWeller_2020_ Analysis _ Name Perception.do for Appendix A Table 7b

*Set working drive to Main filepath (e.g. C:\Documents\) 
cd "-INSERT DESIRED FILE PATH\"

*Load data 
use LandgraveWeller_2020_Audit_Supplemental.dta, clear 

*Set working drive to Table and Figures filepath (e.g. C:\Documents\) 
cd "-INSERT DESIRED FILE PATH\Tables and Figures"

asdoc sum Race_White RParty Gender_Female, replace save(TableA7a.doc)